#ifndef _SPHERE_H
#define _SPHERE_H

#include "Common.h"
#include "Primitive.h"

namespace Pandora
{
	class CSphere : public CPrimitive
	{
		CVector3 centre;
		float sqRadius, radius, rRadius;
	public:
		CSphere(CVector3& cen, float rad) : centre(cen), sqRadius(rad * rad), radius(rad), rRadius(1.0f / rad) {}
		CSphere(CVector3* cen, float rad) : centre(*cen), sqRadius(rad * rad), radius(rad), rRadius(1.0f / rad) {}
		CSphere(float x, float y, float z, float rad) : centre(CVector3(x, y, z)), sqRadius(rad * rad), radius(rad), rRadius(1.0f / rad) {}

		CVector3& GetCentre() { return centre; }
		CVector3& GetPosition() { return centre; }
		float GetSqRadius() { return sqRadius; }
		float GetRadius() { return radius; }
		CVector3 GetNormal(CVector3& pos) { return ((pos - centre) * rRadius); }
		CVector3 GetNormal(CVector3* pos) { return ((*pos - centre) * rRadius); }
		PRIMITIVES GetType() { return SPHERE; }

		int Intersect(CRay& ray, float &t);
		int Intersect(CRay* ray, float &t);

		void  SetCentre(CVector3& c) { centre = c; }
		void  SetCentre(CVector3* c) { centre = *c; }
		void  SetCentre(float x, float y, float z) { centre = CVector3(x, y, z); }
	};

}; //namespace Pandora

#endif /* _SPHERE_H */